package com.bea.ftd.mapping.message;

import java.io.IOException;

import com.bea.ftd.common.entity.MsgInConf;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;


public class JsonUtils {
    private static ObjectMapper objectMapper = new ObjectMapper();
    static {
        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
    }
    /**
     * Json内容转化为对象
     * @param content
     * @param valueType
     * @param <T>
     * @return
     * @throws IOException
     */
    public static  <T> T  readValue(String content, Class<T> valueType) throws IOException {
        return objectMapper.readValue(content,valueType);
    }
    /**
     * 对象转化为Json内容
     * @param t
     * @param <T>
     * @return
     * @throws IOException
     */
    public static  <T> String  writeValueAsString(T t) throws IOException {
        return objectMapper.writeValueAsString(t);
    }


    public static void main(String[] args) throws IOException {
        String jsonString = "{\"apiId\":1,\"msgInType\":1,\"paramName\":\"head\",\"paramNote\":\"aaa\"}";
        String rootClassPath = Thread.currentThread().getContextClassLoader ().getResource("").getPath();

        System.out.println(jsonString);
        MsgInConf msgInConf = readValue(jsonString,MsgInConf.class);
        String xml = XmlUtils.writeValueAsString(msgInConf);
        System.out.println(xml);
    }


}
